<?php
namespace App\Http\Controllers\Admin\User;

use App\Http\Controllers\Admin\BaseController;
use Illuminate\Support\Facades\Redirect;
use Illuminate\Http\Request;

class CompanyController extends BaseController
{
     protected  $api_url = [
        'index' => ['get', 'company'],
        'show' => ['get', 'company/%d'],
        'store' => ['post', 'company'],
        'put' => ['put', 'company/%d'],
        'delete' => ['delete', 'company/%d']
    ];

    protected $request;

    public function __construct(Request $request)
    {
        $this->request = $request;
    }

    public function indexAction(){
    }

    public function showAction($id){

    }


    //ajax提交
    public function updateAction($id)
    { 
        $this->validate($this->request, [
            'update_type' => 'required',
            'fail_reason' => 'sometimes|required'
        ]);
        $data = $this->request->all();
        $params['update_type'] = $data['update_type'];
        
        if($data['update_type'] == 'update_step'){
            $params['step'] = 2;
        }elseif ($data['update_type'] == 'update_fail_reason') {
           $params['step'] = 3;
           $params['fail_reason'] = $data['fail_reason'];
        }
        
        return $this->update($id, $params);
    }

    //update公共方法
    private function update($id, $data)
    {
        $ret = http_admin($this->api_url['put'],[$id])->send($data);
        return $ret;
    }




}